﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NCacheDServer.CacheStore
{
    internal sealed class CacheItem
    {
        public DateTime LastAccessed { get; set; } // maybe to be used in the future for diagnostics or to priorize cache items
        public int accessCount;
        public int AccessCount { get { return accessCount; } }       // ditto


        public void IncrementAccessCount()
        {
            System.Threading.Interlocked.Increment(ref accessCount);
        }

        public DateTime Expiration { get; set; }
        public byte[] Value {get; set;}

        public CacheItem()
        {
            LastAccessed = DateTime.Now;
        }

        public CacheItem(byte[] value, DateTime expiration) : this()
        {
            Expiration = expiration;
            Value = value;
        }

        public bool IsValid()
        {
            return DateTime.Now < this.Expiration;
        }
    }

}
